<template>
    <h2>添加房型</h2>
    <table border="1">
        <tr>
            <td>房型名称：</td>
            <td>
                <input type="text" v-model="info.tName"/>
            </td>
        </tr>
        <tr>
            <td>售价：</td>
            <td>
                <input type="text" v-model="info.tMoney"/>
            </td>
        </tr>
        <tr>
            <td>房型面积</td>
            <td>
                <input type="text" v-model="info.tMianJi"/>
            </td>
        </tr>
        <tr>
            <td>可住人数</td>
            <td>
                <input type="text" v-model="info.person"/>
            </td>
        </tr>
        <tr>
            <td>房型图片</td>
            <td>
                <img :src="info.imgurl" style="width:70px;height:70px;"/>
                <input type="file" @change="Tu"/>
            </td>
        </tr>
        <tr>
            <td>房型介绍</td>
            <td>
                <textarea v-model="info.tInfo">

                </textarea>
            </td>
        </tr>
        <tr>
            <td>可否加床</td>
            <td>
                <input type="radio" :value="true" v-model="info.isChuang"/>免费加床
                <input type="radio" :value="false" v-model="info.isChuang"/>不可加床
            </td>
        </tr>
        <tr>
            <td>是否含早</td>
            <td>
                <input type="radio" :value="true" v-model="info.isBreakFast"/>含早
                <input type="radio" :value="false" v-model="info.isBreakFast"/>不含早
            </td>
        </tr>
        <tr>
                <input type="button" value="添加" @click="Add"/>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRouter,useRoute} from 'vue-router';
    const route=useRoute();
    const router=useRouter();

    const info=ref({
        tName: "",
        tMoney: 0,
        tMianJi: 0,
        person: 0,
        imgurl: "",
        tInfo: "",
        isChuang: true,
        isBreakFast: true
    });

    const Add=()=>{
        axios.post("https://localhost:7029/api/RoomType/AddRoomTYpe/AddRoomTYpe",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
            }
            else if(res.data==-1){
                alert('已存在');
            }
            else{
                alert('添加失败');
            }
        })
    }

    const Tu=(e:any)=>{
        var file=e.target.files[0];
        var fd=new FormData();
        fd.append("Files",file);
        axios.post("https://localhost:7029/api/File/Tu",fd)
        .then(res=>{
            console.log(res.data);
            info.value.imgurl=res.data;
        })
        .catch(err=>{
            console.log(err);
        })
    }

</script>
